﻿using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;

namespace PingInfo.avalonia.Models
{
    public class IpEntity : ObservableObject
    {
        private IBrush? _background;
        private long _delay;
        private string? _log;
        private double _width;

        public string? Ip { get; set; }

        public double Width
        {
            get => _width;
            set => SetProperty(ref _width, value);
        }

        public long Delay
        {
            get => _delay;
            set
            {
                SetProperty(ref _delay, value);
                ChangeColorByDelay(_delay);
            }
        }

        public IBrush Background
        {
            get => _background ??= Brushes.LightGray;
            set => SetProperty(ref _background, value);
        }

        public string? Log
        {
            get => _log;
            set => SetProperty(ref _log, value);
        }


        private void ChangeColorByDelay(long a)
        {
            Background = a switch
            {
                -1 => Brushes.LightGray,
                < 0 => Brushes.Transparent,
                <= 50 => Brushes.LightGreen,
                <= 100 => Brushes.Gold,
                _ => Brushes.LightSalmon
            };
        }
    }
}